#coding:utf-8
class MessageServer(object):
    def __init__(self):
        self.observers = []#所有在线用户列表

    def _poll_to_all_user(self, msg):
        print("_poll_to_all_user:",msg)
        for ws in self.observers:
            print ws
            try:
                ws.send(msg)
            except:
                self.observers.pop(self.observers.index(ws))#失败就从所有用户列表里删除
                print ws, 'is closed'
                continue
    def Return_To_User(self,usr,msg):
        usr.send(msg)#直接发送回去
    def _set_observer(self,obj):
        self.observers = obj
